﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Glossary
{
    /// <summary>
    /// Ansvar: Vikiet Chung
    /// </summary>
    public static class TestCorrecter
    {
        public static CorrectedTest Correct(FilledTest filledTest, WordLibrary wordLibrary, bool ignoreCase)
        {
            CorrectedTest correctedTest = new CorrectedTest(filledTest);
            try
            {
                correctedTest.DateOfCorrection = DateTime.Now;
                correctedTest.CaseSensitiveCorrection = !ignoreCase;
                for (int i = 0; i < correctedTest.NumberOfWords; i++)
                {
                    correctedTest.Words[i].ForeignWord = wordLibrary.GetForeignWord(correctedTest.LanguageOfTest, correctedTest.Words[i].SwedishWord);

                    if (string.Compare(filledTest.StudentAnswers[i], correctedTest.Words[i].ForeignWord,
                        ignoreCase) == 0)
                    {
                        correctedTest.AnswerIsCorrect[i] = true;
                        correctedTest.Score++;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return correctedTest;
        }
    }
}
